import { App, createVNode, render } from 'vue'
import Loading from './index.vue'

export default {
  install: (app: App) => {
    // 根据vue组件，创建虚拟节点
    const vNode = createVNode(Loading)
    // 渲染虚拟节点
    render(vNode, document.body)
    const gykLoading = (msg?: string) => {
      if (msg) {
        vNode.component?.exposed?.editMessage(msg)
      }
      vNode?.component?.exposed?.show()
    }
    gykLoading.show = vNode?.component?.exposed?.show;
    gykLoading.hide = vNode?.component?.exposed?.hide;
    // 添加一个全局属性
    app.config.globalProperties.$GYKLoading = gykLoading;
  }
}